Process Analysis Toolkit (PAT) 3.5 Help |
Some complicated calculations (e.g., algorithms, data operations and
computations) are difficult to implement in PAT's modeling language. It is
easier to write them using programming language like C#. We provide user such
option to implement the calculations using C# static methods and invoke these
methods in PAT. The following is one simple example of showing how to write static methods in
C#.
using System.Collections.Generic;
using
PAT.Common.Classes.Expressions.ExpressionClass;
// the
namespace must be PAT.Lib, the class and method names can be
arbitrary
namespace PAT.Lib {
public class
PatList {
public
static int[] ListAdd(int[] list, int
element) {
List<int> newList = new
List<int>(list);
newList.Add(element);
return
newList.ToArray();
}
public static bool
ListContains(int[] list, int
element) {
foreach (int i in
list) {
if (i ==
element) {
return
true;
}
}
return
false;
}
}
}
Note the following requirements when you create your own libraries:
If your methods need to handle exceptional cases, you can throw PAT runtime exceptions as illustrated as the following example.
public static int StackPeek(int[] array) {
if (array.Length > 0)
return array[array.Length - 1];//throw PAT Runtime exception
throw new PAT.Common.Classes.Expressions.ExpressionClass.RuntimeException("Access an empty stack!");
}
To import the libraries in your model, users can using following syntax:
Note: the method names are case sensitive. The build-in C# math functions you can use are listed as follows: